package _interview75;

/**
 * 1456. 定长子串中元音的最大数目
 */
public class No1456 {
    private String s;

    public int maxVowels(String s, int k) {
        this.s = s;
        int n = s.length();
        int answer = 0;

        for (int i = 0; i < k; i++) {
            if (isVowel(i)) answer++;
        }

        int curNum = answer;
        for (int left = 0, right = k; right < n; left++, right++) {
            if (isVowel(left)) curNum--;
            if (isVowel(right)) curNum++;
            answer = Math.max(curNum, answer);
        }
        return answer;
    }

    private boolean isVowel(int i) {
        String str = "aeiou";
        return str.indexOf(s.charAt(i)) > -1;
    }
}
